Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tracker health check client #378

Closed
wants to merge 7 commits into from

Conversation

Anton-Kalpakchiev
Copy link
Collaborator

As described in #371, all services should implement a "readiness" endpoint, which checks whether the service is ready to serve traffic, i.e. whether it can reach all of its dependencies. The agent's readiness endpoint will check whether it has any healthy trackers available (as it needs to query a tracker to get data about where a torrent can be found). Thus, the agent needs a client for the tracker's health endpoint.

Add health check client endpoint for tracker, which queries its health endpoint.

Stacked on top of #377

@@ -89,6 +92,18 @@ func getEndpoint(version int, addr string, h core.InfoHash) (method, url string)
return "POST", fmt.Sprintf("http://%s/announce/%s", addr, h.String())
}

func (c *client) CheckHealth() error {
addr := c.ring.Locations(backend.ReadinessCheckDigest)[0]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity check to see if the ring Locations is not empty.

locations := c.ring.Locations(backend.ReadinessCheckDigest)
if len(locations) == 0 {
    return fmt.Errorf("no locations available for health check")
}
addr := locations[0]

addr := c.ring.Locations(backend.ReadinessCheckDigest)[0]
_, err := httputil.Get(
fmt.Sprintf("http://%s/health", addr),
httputil.SendTimeout(2*time.Second),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making this configurable would be a nice to have.

Copy link
Collaborator

@gkeesh7 gkeesh7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments rest Looks good to me.

@Anton-Kalpakchiev
Copy link
Collaborator Author

Turns out that the tracker's readiness is not equal to its health. The tracker must check the origin's readiness. Thus a client for the health endpoint is not required. Instead a readiness endpoint will be implemented in #380

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants